package org.jeecg.modules.system.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.jeecg.common.util.SsoUtil;
import org.jeecg.modules.system.entity.SysScope;
import org.jeecg.modules.system.mapper.SysScopeMapper;
import org.jeecg.modules.system.service.ISysScopeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.Date;
import java.util.List;

/**
 * @Description: 作用域管理
 * @Author: jeecg-boot
 * @Date:   2019-10-05
 * @Version: V1.0
 */
@Service
public class SysScopeServiceImpl extends ServiceImpl<SysScopeMapper, SysScope> implements ISysScopeService {

    @Autowired
    private SysScopeMapper sysScopeMapper;

    @Override
    public List<SysScope> findByName(String scopeName,String scopeId) {
        return sysScopeMapper.findByName(scopeName,scopeId);
    }

    @Override
    public SysScope getByScopeType(Integer roleType) {
        return sysScopeMapper.getByScopeType(roleType);
    }

    @Override
    public List<SysScope> getByIds(List<String> ids) {
        return sysScopeMapper.getByIds(ids);
    }

    @Override
    public List<SysScope> queryServerScopeTreeList(String tenantId) {
        return sysScopeMapper.queryServerScopeTreeList(tenantId);
    }

    @Override
    public IPage<SysScope> findServerPage(Page<SysScope> page, SysScope sysScope) {
        return sysScopeMapper.findServerPage(page,sysScope);
    }

    @Override
    public void serverSave(SysScope sysScope) {
        sysScope.setId(String.valueOf(IdWorker.getId()));
        sysScope.setCreateBy(SsoUtil.getLoginUser().getId());
        sysScope.setCreateTime(new Date());
        sysScope.setUpdateBy(SsoUtil.getLoginUser().getId());
        sysScope.setUpdateTime(new Date());
        sysScope.setDelFlag("0");
        sysScopeMapper.serverSave(sysScope);
    }
}
